﻿#pragma once

//#include "TLCommon.h"
#include "WebSocketClient.h"
#include <Windows.h>
#include <string>
#include <memory>
#include <map>
#include "GameCore.h"


class CGameData
{
public:
	CGameData();

	//更新数据入口.
	void Update();

	//发送周围对象
	void SendRangeActors(WebSocketClient* pClient);

	////发送效果数组
	void SendEffects(WebSocketClient* pClient);

	////bool m_SendQuickSlotSignal{false};
	//发送快捷栏数组
	void SendQuickSlot(WebSocketClient* pClient);

	////发送背包数组
	//void SendInventory(WebSocketClient* pClient);

	//发送 遍历冒险，探查任务库
	void SendTaskAdventureExploration(WebSocketClient* pClient , int requestId, const std::vector<CTaskSharedPtr>& tasks);

	//发送 当前已接委托任务
	void SendTaskDelegation(WebSocketClient* pClient , int requestId, const std::vector<CTaskSharedPtr>& tasks);

	CActorSharedPtr GetLocalPlayerActor();

public:

	//更新全局UE对象
	void UpdateGlobalVars();

	//遍历周围对象
	//Warning: std::lock_guard<std::mutex> lock(m_mutex); must be used before accessing m_LocalPlayerActor and m_actors
	void UpdateRangeActors();

	//遍历本地玩家对象
	void UpdateActorsInternal(std::vector<CActorSharedPtr>& actors);

	//遍历技能
	void UpdateSkill(std::vector<CSkillSharedPtr>& skills);

	//遍历背包
	void UpdateInventory(std::vector<CItemSharedPtr>& m_items);

	//遍历冒险，探查任务库
	void GetTaskAdventureExploration(std::vector<CTaskSharedPtr>& tasks);

	//遍历当前已接委托任务
	void GetTaskDelegation(std::vector<CTaskSharedPtr>& tasks);

	//遍历快捷栏数组
	void UpdateQuickSlot();

	//更新本地玩家效果数组
	void UpdateActorEffect(std::vector<SEffectSharedPtr>& Effect);

	//遍历SWidget
	void UpdateSWidget();

	//更新传送点
	void UpdateTeleportPoint(std::vector<STeleportPointSharedPtr>& TeleportPoints);

	//查找日程表
	void UpdateSchedule(std::vector<SScheduleSharedPtr>& SSchedules);

	//遍历队伍
	void UpdatePartyInfo(std::vector<SPartyInfoSharedPtr>& partyInfoS);
		

public:
	CActorSharedPtr m_LocalPlayerActor;

	std::vector<STeleportPointSharedPtr> m_teleports;

	//周围对象数组
	std::vector<CActorSharedPtr> m_actors;

	//本地玩家效果数组
	std::vector<SEffectSharedPtr> m_effects;

	//快捷栏槽数组
	std::vector<CQuickSlotSharedPtr> m_quickSlot;

	//冒险，探查任务库数组
	//std::vector<CTaskSharedPtr> m_taskAdventureExploration;

	//委托任务库数组
	//std::vector<CTaskSharedPtr> m_taskDelegation;

	std::mutex m_mutex_call;
	TaskCall* m_MainCall = 0;
	TaskCall* GetCall();
	void AddCall(TaskCall* call);

	//线程锁，防止游戏主线程与webSocket线程读写数据冲突
	std::mutex m_mutex;

	//技能攻击速度表
	std::map<int, float> m_skillAttackSpeed;

	//msgpack::sbuffer m_sendbuf;
};


extern CGameData g_GameData;